/**
 * 
 */
package wdmsim;

import tracing.OBGPTracer;
import tracing.Trace;
import tracing.Tracer;
import controlPlane.*;
import events.*;


/**
 * @author alissonslp
 *
 */
public class SimulationRunner {

	/**
	 * 
	 * @throws Exception 
	 */
	public SimulationRunner() throws Exception {
		
		EventScheduler scheduler = EventScheduler.getInstance();
		Trace tr = null;
		if(Simulator.RWA_MODE.matches("pce-based")) {
			tr = Tracer.getTracerObject();
		} else {			
			// define controlPlane type
			tr = OBGPTracer.getTracerObject();
		}
        Event event;
    	Handler handler;
        
        while ((event = scheduler.popEvent()) != null) {
            Simulator.CURRENT_TIME = event.getTime();
            tr.addEvent(event);
            handler = event.getHandler();
            if (handler == null) {
        		System.out.println("Scheduled an event without a handler. Don't do that.");
        		throw new Exception();
        	}
            handler.handle(event);
        }
	}
}
